﻿using System;

namespace Godot.core
{
    public partial class Variant
    {
        public enum Operator 
        {
		    //comparation
		    OP_EQUAL,
		    OP_NOT_EQUAL,
		    OP_LESS,
		    OP_LESS_EQUAL,
		    OP_GREATER,
		    OP_GREATER_EQUAL,
		    //mathematic
		    OP_ADD,
		    OP_SUBSTRACT,
		    OP_MULTIPLY,
		    OP_DIVIDE,
		    OP_NEGATE,
		    OP_MODULE,
		    OP_STRING_CONCAT,
		    //bitwise
		    OP_SHIFT_LEFT,
		    OP_SHIFT_RIGHT,
		    OP_BIT_AND,
		    OP_BIT_OR,
		    OP_BIT_XOR,
		    OP_BIT_NEGATE,
		    //logic
		    OP_AND,
		    OP_OR,
		    OP_XOR,
		    OP_NOT,
		    //containment
		    OP_IN,
		    OP_MAX
	    }

        protected static string [] op_names =
        #region ____op_names____
        {
	        "==",
	        "!=",
	        "<",
	        "<=",
	        ">",
	        ">=",
	        "+",
	        "-",
	        "*",
	        "/",
	        "- (negation)",
	        "%",
	        "..",
	        "<<",
	        ">>",
	        "&",
	        "|",
	        "^",
	        "~",
	        "and",
	        "or",
	        "xor",
	        "not",
	        "in"

        };
        #endregion

        public static string get_operator_name(Operator p_op) 
        {
            if(p_op >= Operator.OP_MAX || !Enum.IsDefined(typeof(Operator), p_op))
	            return "";
	        return op_names[(int)p_op];
        }

        public Variant get(Variant p_index, ref bool r_valid)
        {
            r_valid = false;
            
	        switch(type) 
            {
		        case Variant.Type.NIL: {  return new Variant();  } break;
		        
                case Variant.Type.BOOL: { return new Variant();  } break;
		        
                case Variant.Type.INT: {  return new Variant();  } break;
		        
                case Variant.Type.REAL: {  return new Variant();  } break;
		        
                case Variant.Type.STRING: {

			        if (p_index.type == Variant.Type.INT || p_index.type == Variant.Type.REAL) 
                    {
				        //string index

				        int idx = p_index;
				        string str = (string)_data;
				        if (idx >= 0 && idx < str.Length) 
                        {
					        r_valid = true;
					        return str.Substring(idx, 1);
				        }
			        }

		        } break;

                default: break;
            }
            return null;
        }

        public Variant get_named(StringName p_index, ref bool r_valid)
        {
            if (_type == Variant.Type.OBJECT)
            {
                ((Object)_data).get(p_index, ref r_valid);
            }
            return get((string)p_index, ref r_valid);
        }

        public static void evaluate(Variant.Operator p_op, Variant p_a, Variant p_b, ref Variant r_ret, ref bool r_valid) 
        {
        }
    }
}
